﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;

namespace XMLBasicStudy
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string pPath = this.Server.MapPath("~/demo.xml");
            XmlReader reader = XmlReader.Create(pPath);

            reader.ReadToFollowing("price");
            string typeInfo = reader.NodeType.ToString();
            string authorInfo = reader.ReadString();

            this.Literal1.Text = typeInfo + " " + authorInfo;
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            string pPath = this.Server.MapPath("~/demo.xml");
            XmlReader reader = XmlReader.Create(pPath);

            reader.ReadToFollowing("book");
            this.Literal1.Text = reader.ReadOuterXml();
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            XmlReaderSettings settings = new XmlReaderSettings();
            settings.IgnoreWhitespace = true;
            string pPath = this.Server.MapPath("~/bookstore.xml");
            using (XmlReader reader = XmlReader.Create(pPath, settings))
            {

                // Moves the reader to the root element.
                reader.MoveToContent();

                // Moves to book node.
                reader.Read();

                // Note that ReadInnerXml only returns the markup of the node's children
                // so the book's attributes are not returned.
                this.Literal1.Text= (reader.ReadInnerXml());

            }
        }

        protected void Button4_Click(object sender, EventArgs e)
        {
            XmlReaderSettings settings = new XmlReaderSettings();
            settings.IgnoreWhitespace = true;
            string pPath = this.Server.MapPath("~/bookstore.xml");
            using (XmlReader reader = XmlReader.Create(pPath, settings))
            {

                // Moves the reader to the root element.
                reader.MoveToContent();

                // Moves to book node.
                reader.Read();

                // Note that ReadInnerXml only returns the markup of the node's children
                // so the book's attributes are not returned.
                this.Literal1.Text = (reader.ReadOuterXml());

            }
        }
    }
}
